
import { PageInstanceVO, Response } from '@/api/type';
import request from '@/utils/request';
import type { SaleAttrList, SpuImageList, SpuSaleAttrList, SpuVO } from './type';
import type { TrademarkList } from '../trademark/type';
import { SkuList, SkuParam } from '../sku/type';

enum API {
  //  获取spu列表
  SPU_LIST = '/admin/product/spu/list',
  //  删除spu
  SPU_DELETE = '/admin/product/spu/delete',
  //  获取spu详情
  SPU_INFO = '/admin/product/spu/info',

  //  获取spu图片列表
  SPU_IMAGE_LIST = '/admin/product/spu/image/list',
  // 获取全部品牌的数据
  ALL_TRADEMARK_URL = '/admin/product/baseTrademark/list',
  // 获取某个spu下的全部的售卖上面的图片数据
  SPU_IMAGE_URL = '/admin/product/spu/spuImageList',
  // 获取某一个spu下全部的已有的销售属性接口地址
  SPU_SALE_ATTR_LIST = '/admin/product/spu/saleAttr/list',
  // 获取整个项目全部的销售属性【颜色，尺码，版本】
  ALL_SALE_ATTR_URL = '/admin/product/baseSaleAttrList',
  // 添加 新的spu数据
  SAVE_SPU_INFO_ULR = '/admin/product/spu/saveSpuInfo',
  // 更新新的spu数据
  UPDATE_SPU_INFO_URL = '/admin/product/spu/updateSpuInfo',
  // 追加一个新增的SKU地址
  ADD_SKU_URL = '/admin/product/spu/saveSkuInfo',
  // 查看某一个已有的spu下全部售卖商品
  SPU_SKU_LIST = '/admin/product/spu/list',
}




// 查询spu列表
export const reqSpuList = async (page: number, limit: number, category3Id: number) => request.get<any, Response<PageInstanceVO<SpuVO>>>(
  API.SPU_LIST,
  {
    params: {
      page,
      limit,
      category3Id,
    }
  }
)

//  获取spu详情
export const reqSpuInfo = async (spuId: number) => request.get<any, Response<SpuVO>>(
  `${API.SPU_INFO}/${spuId}`
)

//  删除spu
export const reqDeleteSpu = async (spuId: number) => request.delete<any, Response<void>>(
  `${API.SPU_DELETE}/${spuId}`
)


// 获取全部的SPU的品牌的接口
export const reqAllTrademarkList = async () => request.get<any, Response<TrademarkList>>(API.ALL_TRADEMARK_URL)
// 获取某个spu下的全部的售卖上面的图片数据
export const reqSpuImageList = async (spuId: number) => request.get<any, Response<SpuImageList>>(`${API.SPU_IMAGE_URL}/${spuId}`)


//  获取spu销售属性列表
export const reqSpuSaleAttrList = async (spuId: number) => request.get<any, Response<SpuSaleAttrList>>(
  `${API.SPU_SALE_ATTR_LIST}/${spuId}`
)
//  获取整个项目全部的销售属性【颜色，尺码，版本】
export const reqAllSaleAttrList = async () => request.get<any, Response<SaleAttrList>>(API.ALL_SALE_ATTR_URL)

// 新增spu的相关属性
const reqSaveSpuInfo = async (data: SpuVO) => request.post<any, Response<void>>(API.SAVE_SPU_INFO_ULR, data)

//  更新spu的相关属性
const reqUpdateSpuInfo = async (data: SpuVO) => request.post<any, Response<void>>(API.UPDATE_SPU_INFO_URL, data)

// 添加一个或者更新一个新的spu
export const reqSaveOrUpdateSpu = (data: SpuVO) => {
  if (data.id) {
    return reqUpdateSpuInfo(data);
  }
  return reqSaveSpuInfo(data)
}
// 添加sku的请求方法
export const reqAddSku = async (data: SkuParam) => request.post<any, Response<void>>(API.ADD_SKU_URL, data)
// 获取某一个已有的spu下全部售卖商品
export const reqSpuSkuList = async (spuId: number) => request.get<any, Response<SkuList>>(`${API.SPU_SKU_LIST}/${spuId}`)
